<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>前台管理</title>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		//初始化数据表格
		$('#patient_index_datagridT').datagrid({
			url : '${pageContext.request.contextPath}/patientAction!findPatient.action',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'patientId',
			pageSize : 12,
			pageList : [ 12, 24, 36, 48, 60 ],
			sortName : 'patientDate',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			striped : true,
			rownumbers : true,
			singleSelect : true,
			columns : [ [ {
				field : 'todayid',
				align : 'center',
				title : '挂号单单号',
				width : 150
			}, {
				field : 'patientName',
				align : 'center',
				title : '病人姓名',
				width : 150,
				sortable : true
			}, {
				field : 'patientAge',
				align : 'center',
				title : '病人年龄',
				width : 150,
				sortable : true
			}, {
				field : 'patientDate',
				align : 'center',
				title : '挂号时间',
				width : 150,
				sortable : true
			}, {
				field : 'sex',
				align : 'center',
				title : '病人性别',
				width : 150,
				sortable : true
			}, {
				field : 'patientPrice',
				align : 'center',
				title : '挂号费',
				width : 150
			}, {
				field : 'doctorName',
				align : 'center',
				title : '医生姓名',
				width : 150
			}

			] ],
			toolbar : [ {
				text : '挂号',
				iconCls : 'icon-add',
				handler : function() {
					append();
				}
			}, '-', {
				text : '换号',
				iconCls : 'icon-remove',
				handler : function() {
					remove();
				}
			}, '-', {
				text : '退号',
				iconCls : 'icon-edit',
				handler : function() {
					clearFun();
				}
			}, '-' ]

		});

	});
	//模糊查询
	function searchFun() {
		$('#patient_index_datagridT').datagrid('load', {
			inputText : $('#search').val()
		});
	}
	//退号
	function clearFun() {
		var rows = $('#patient_index_datagridT').datagrid('getSelected');
		if (rows == null) {
			$.messager.alert('提示', '请选择一个选项', 'error');
		} else {
			$.messager.confirm('确认', '您是否需要退号业务？', function(r) {
				if (r) {
					$.ajax({
						url : '${pageContext.request.contextPath}/patientAction!deleteById.action',
						type : "POST",
						data : {
							patientId : rows.patientId
						},
						success : function(d) {
							var obj = jQuery.parseJSON(d);
							if (obj.success) {
								$('#patient_index_datagridT').datagrid('reload');
								$.messager.show({
									title : '提示',
									msg : '成功退号'
								});
							} else {
								$.messager.show({
									title : '提示',
									msg : '你已经看了病了，不能再换号了'
								});
							}
						}
					});
				}
			});
		}
	}
	//显示添加窗口
	function append() {
		$('#patient_index_addForm input').val('');
		$('#patient_index_addDialog').dialog('open');
	}
	//换号
	function remove() {
		var rows = $('#patient_index_datagridT').datagrid('getSelected');
		if (rows == null) {
			$.messager.alert('提示', '请选择一个选项', 'error');
		} else {
			$.messager.confirm('确认', '您是否需要换号业务？', function(r) {
				if (r) {
					$.ajax({
						url : '${pageContext.request.contextPath}/patientAction!deleteById.action',
						type : "POST",
						data : {
							patientId : rows.patientId
						},
						success : function(d) {
							var obj = jQuery.parseJSON(d);
							if (obj.success) {
								append();
							} else {
								$.messager.show({
									title : '提示',
									msg : '你已经看了病了，不能再换号了'
								});
							}
						}
					});
				}
			});
		}
	}
</script>

</head>

<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'north',split:true" style="height: 47px;">
		模糊查询用户姓名: <input id="search" class="easyui-textbox" type="text"><a href="javascript:void(0)" onclick="searchFun()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
	</div>
	<div data-options="region:'center',split:true">
		<table id="patient_index_datagridT">

		</table>
	</div>
	<!--  -->

	<div id="patient_index_addDialog" class="easyui-dialog" data-options="closed:true,modal:true,title:'添加挂号单',buttons:[{
				text : '增加',
				iconCls : 'icon-add',
				handler : function() {
					$('#patient_index_addForm').form('submit', {
						url : '${pageContext.request.contextPath}/patientAction!savePatient.action',
						success : function(r) {
							var obj = jQuery.parseJSON(r);
							$('#patient_index_datagridT').datagrid('reload');
							$('#patient_index_addDialog').dialog('close');
							$.messager.show({
								title : '提示',
								msg : obj.msg
							});
						}
					});
				}
			}]" style="width: 280px;height:300px;" align="center">

		<form id="patient_index_addForm" method="post">
	
			<table>
				<tr>
					<th>科室：</th>
					<td><input class="easyui-combobox easyui-textbox" data-options="
						url:'${pageContext.request.contextPath}/officeAction!findAll.action',
						valueField: 'value',
						textField: 'text',
						onSelect: function(rec){
							var url='userAction!findOfficeUser.action?ofid='+rec.value;
							$('#patient_index_addDialog_doctor').combobox('reload',url);
						}
						" /></td>
				</tr>
				<tr>
					<th>医生：</th>
					<td><input id="patient_index_addDialog_doctor" name="doctorId" class="easyui-combobox easyui-textbox" data-options="valueField: 'value',textField: 'text',
						onSelect: function(rec){
							var url='userAction!getUserPrice.action?userid='+rec.value;
							$.ajax({
								type:'POST',
								url:url,
								success:function(msg){
									var obj = jQuery.parseJSON(msg);
									$('#patient_index_price').val(obj.obj); 
								
								}
								
							});
							
						}
					" /></td>
				</tr>
				<tr>
					<th>姓名：</th>
					<td><input type="text" name="patientName" class="easyui-textbox easyui-validatebox" data-options="required:true" /></td>
				</tr>
				<tr>
					<th>性别：</th>
					<td><input name="patientSex" class="easyui-combobox easyui-textbox" data-options="valueField: 'value',textField: 'text',url:'${pageContext.request.contextPath}/sex.json'" /></td>
				</tr>
				<tr>
					<th>年龄：</th>
					<td><input type="text" name="patientAge" class="easyui-validatebox easyui-textbox" data-options="required:true" /></td>
				</tr>
				<tr>
					<th>价格：</th>
					<td><input type="text" class="easyui-textbox" id="patient_index_price" /></td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>
